/**
  ******************************************************************************
  * @file    Libraries/Device/TS32F020X/TS32F020X_LL_Driver/src/ts32f020x_ll_wdt.c
  * @author  JUSHENG Application Team
  * @version V1.0.0
  * @date    02-19-2022
  * @brief   This file contains all the WDT LL firmware functions.
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2022 JUSHENG</center></h2>
  *
  *
  *
  ******************************************************************************
  */ 

/* Includes ------------------------------------------------------------------*/
#include "include.h"

/** @addtogroup TS32F020X_StdPeriph_Driver TS32F020X Driver
  * @{
  */
  
/** @defgroup wdt_interface_gr WDT Driver
  * @ingroup  TS32F020X_StdPeriph_Driver
  * @{
  */

/** @addtogroup WDT_LL_Driver WDT LL Driver
  * @ingroup  wdt_interface_gr
  * @{
  */
  
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/** @defgroup WDT_LL_Inti_Cfg WDT LL Initialization And Configuration
  * @ingroup  WDT_LL_Driver
  * @brief    WDT LL Initialization And Configuration
  * @{
  */

/**
  * @brief  ll_wdt_feed : use for clear watchdog counter
  * @param  p_wdt: pointer to the hardware WDT_TypeDef *p_wdt
  * @retval None
  */
void ll_wdt_feed(WDT_TypeDef *p_wdt) {
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_FEED_DOG);
}

/**
  * @brief  wdt_init
  * @param  p_wdt : pointer to the hardware WDT_TypeDef
  * @param  p_init: pointer to the init stuct TYPE_LL_WDT_INIT
  * @retval None
  */
void ll_wdt_init(WDT_TypeDef *p_wdt, TYPE_LL_WDT_INIT *p_init)
{
    TX_ASSERT(WDT == p_wdt);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_CLOSE_DOG);
    if(LL_WDT_RMODE_INT == p_init->mode)
    {
        LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_EN_INT);
    }
    else
    {
        LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_DIS_INT);
    }

    LL_WDT_CON_PSR_SET(p_wdt, p_init->psr);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_FEED_DOG);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_START_DOG);
}

/**
  * @brief  wdt_config
  * @param  p_wdt : pointer to the hardware WDT_TypeDef
  * @param  mode: interrupt or reset
  * @param  time_out : watchdog  time out
  * @retval None
  */
void ll_wdt_config(WDT_TypeDef *p_wdt, TYPE_ENUM_LL_WDT_RMODE mode, TYPE_ENUM_LL_WDT_PSR wdt_psc)
{
    TX_ASSERT(WDT == p_wdt);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_CLOSE_DOG);
    if(LL_WDT_RMODE_INT == mode)
    {
        LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_EN_INT);
    }
    else
    {
        LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_DIS_INT);
    }
    LL_WDT_CON_PSR_SET(p_wdt, wdt_psc);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_FEED_DOG);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_START_DOG);
}

/**
  * @brief  wdt_wakeup enable
  * @param  p_wdt : pointer to the hardware WDT_TypeDef
  * @retval None
  */
void ll_wdt_wake_up_enable(WDT_TypeDef *p_wdt)
{
    LL_WDT_KEY_SET(WDT,LL_WDT_KEY_EN_WAKEUP);
}

/**
  * @brief  wdt_wakeup disable
  * @param  p_wdt : pointer to the hardware WDT_TypeDef
  * @retval None
  */
void ll_wdt_wake_up_disable(WDT_TypeDef *p_wdt)
{
    LL_WDT_KEY_SET(WDT,LL_WDT_KEY_DIS_WAKEUP);
}

/**
  * @brief  wdt_deinit
  * @param  p_wdt : pointer to the hardware WDT_TypeDef
  * @retval None
  */
void ll_wdt_deinit(WDT_TypeDef *p_wdt)
{
    TX_ASSERT(WDT == p_wdt);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_FEED_DOG);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_CLOSE_DOG);
}

/**
  * @}
  */

/** @defgroup WDT_LL_Data_Transfers WDT LL Data transfers functions
  * @ingroup  WDT_LL_Driver
  * @brief    WDT LL Data transfers functions 
  * @{
  */

/**
  * @brief  wdt_start
  * @param  p_wdt : pointer to the hardware WDT_TypeDef
  * @retval None
  */
void ll_wdt_start(WDT_TypeDef *p_wdt)
{   
    TX_ASSERT(WDT == p_wdt);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_FEED_DOG);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_START_DOG);
}

/**
  * @brief  wdt stop
  * @param  p_wdt : pointer to the hardware WDT_TypeDef
  * @retval None
  */
void ll_wdt_stop(WDT_TypeDef *p_wdt)
{     
    TX_ASSERT(WDT == p_wdt);

    /* wdt disable */
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_FEED_DOG);
    LL_WDT_KEY_SET(p_wdt, LL_WDT_KEY_CLOSE_DOG);
}


/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/*************************** (C) COPYRIGHT 2022 JUSHENG ***** END OF FILE *****/
